package rr_server;

public class MessageUtil {

	public static String makeIdentificationMsg(int orderConnected) {
		String identificationMsg = "";
		String playerId = "";
		String s1 = "<identification><playerid>";
		String s2 = "</playerid></identification>";

		switch (orderConnected) {
		case 1:
			playerId = "1";
			break;
		case 2:
			playerId = "2";
			break;
		case 3:
			playerId = "3";
			break;
		}

		identificationMsg = s1 + playerId + s2;

		return identificationMsg;
	}

	public static String makeUpdateMsg(int round, int pitcher, int p1Result, int p2Result, int p3Result) {
		String updateMsg;

		String s1 = "<update><roundnumber>";
		String s2 = "</roundnumber><pitcher>";
		String s3 = "</pitcher><player1result>";
		String s4 = "</player1result><player2result>";
		String s5 = "</player2result><player3result>";
		String s6 = "</player3result></update>";

		updateMsg = s1 + round + s2 + pitcher + s3 + p1Result + s4 + p2Result + s5 + p3Result + s6;

		return updateMsg;
	}

	public static String makeErrorMsg(int errorCode) {
		String errorMsg;		
		String s1 = "<error><errorcode>";
		String s2 = "</errorcode></error>";

		errorMsg = s1 + errorCode + s2;

		return errorMsg;
	}

	public static int getOrderCode() {
		double randomNum;
		int orderCode;

		randomNum = 6 * Math.random();

		if (randomNum < 1) {
			orderCode = 1;
		} else if (randomNum < 2) {
			orderCode = 2;
		} else if (randomNum < 3) {
			orderCode = 3;
		} else if (randomNum < 4) {
			orderCode = 4;
		} else if (randomNum < 5) {
			orderCode = 5;
		} else {
			orderCode = 6;
		}

		return orderCode;
	}

}